import React from 'react';
import {
  Form,
  Modal,
  Card,
  Divider,
  Row,
  Col,
  DatePicker,
  Alert
} from 'antd';
import { LwjUpload } from 'components';
import DescriptionList from 'components/DescriptionList';
import { productType } from "utils/enumConfig";
import moment from 'moment';
import styles from './index.less';

const { Description } = DescriptionList;
const FormItem = Form.Item
const PublishAgainCustomizeOrderModal = ({
  dispatch,
  onOk,
  isUpdate,
  currentContractDetail,
  form: {
    getFieldDecorator,
    validateFieldsAndScroll
  },
  ...updateModalProps
}) => {

  const handleSubmit = () => {
    validateFieldsAndScroll((err, values) => {
      if (!err) {
        values.version = currentContractDetail.version;
        values.contractInstalledAt = moment(values.contractInstalledAt).valueOf() ;
        Modal.confirm({
          title: '提示：',
          content: '请确认是否删除了老的方案以及上传了新的方案!',
          cancelText: '取消',
          okText: '确认',
          onOk() {
            onOk(values);
          },
          onCancel() {

          },
        })
      }
    });
  };

  const modalOpts = {
    ...updateModalProps,
    onOk: handleSubmit
  }

  const xlsProps = {
    maxfile: 1,
    target: '/services/upload/order',
    uploadIcon: 'upload',
    fileType: '',
    onChange(value) {
    },
    showUploadList: true
  }
  const formItemLayout = {
    labelCol: {
      xs: { span: 3 },
      sm: { span: 3 },
    },
    wrapperCol: {
      xs: { span: 10 },
      sm: { span: 10 },
    },
  };
  return (
    <Modal {...modalOpts}>
      {(!_.isEmpty(currentContractDetail) && currentContractDetail.status === "OMS_FACTORY_AUDIT_FAILED") && <Card className={styles.card} bordered={false}>
        <DescriptionList
          title="成品下单信息"
          size="small">
          <Description term="合同号">{currentContractDetail.contractNum}</Description>
          <Description term="产品类型">{productType[currentContractDetail.orderPublishInfoSummary.productType]}</Description>
          <Description term="合同金额">{currentContractDetail.orderPublishInfoSummary.contractAmount}</Description>
          <Description term="合同签订时间">{moment(currentContractDetail.orderPublishInfoSummary.contractSignedAt).format("YYYY-MM-DD HH:mm:ss")}</Description>
          {/* <Description term="合同安装时间">{moment(currentContractDetail.orderPublishInfoSummary.contractInstalledAt).format("YYYY-MM-DD HH:mm:ss")}</Description> */}
          <Description term="收货人姓名">{currentContractDetail.orderPublishInfoSummary.receiptUserName}</Description>
          <Description term="收货人手机号">{currentContractDetail.orderPublishInfoSummary.receiptUserPhoneNum}</Description>
          <Description term="收货人地址">{currentContractDetail.orderPublishInfoSummary.receiptAddress}</Description>
          <Description term="备注">{currentContractDetail.orderPublishInfoSummary.memo}</Description>
          <Description term="工艺审核不通过原因">{currentContractDetail.omsFactoryAuditFailedReason}</Description>
        </DescriptionList>
        <Divider style={{ marginBottom: 32 }} />
        <div className={styles.title}>请填写合同安装时间</div>
        <Form onSubmit={handleSubmit} hideRequiredMark>
          <Row>
            <FormItem {...formItemLayout} label="合同安装时间">
              {getFieldDecorator('contractInstalledAt', {
                rules: [
                  {
                    required: true,
                    message: '请填写合同安装时间',
                    type: 'object'
                  }
                ],
                initialValue: moment(currentContractDetail.orderPublishInfoSummary.contractInstalledAt)
              })(<DatePicker style={{ width: '100%' }} />)}
            </FormItem>
            <div className={styles.title}>请重新上传附件</div>
            <FormItem {...formItemLayout} label="CAD图纸">
              {getFieldDecorator('cadAttachment', {
                rules: [
                  {
                    required: true,
                    message: '请重新上传CAD图纸',
                  }
                ],
                initialValue: currentContractDetail.designAttachment
              })( currentContractDetail.designAttachment && <LwjUpload multiple={true} {...xlsProps} fileLists={currentContractDetail.designAttachment} />)}
            </FormItem>
            <FormItem {...formItemLayout} label="报价单">
              {getFieldDecorator('finalAccountsAttachment', {
                rules: [
                  {
                    required: true,
                    message: '请重新上传报价单',
                  }
                ],
                initialValue: currentContractDetail.orderQuoteSummary.quoteAttachment
              })(<LwjUpload multiple={true} {...xlsProps} fileLists={currentContractDetail.orderQuoteSummary.quoteAttachment} />)}
            </FormItem>
          </Row>
          <Alert
            message="提示："
            description="如果方案有变化请删除老的方案并上传新的方案！"
            type="error"
          />
        </Form>

      </Card>}
    </Modal>
  )
}

export default Form.create()(PublishAgainCustomizeOrderModal);
